#include <cuda.h>

#include "cuda-play/simple/reduce.h"

namespace {
template <typename T>
__global__ T k_reduce(T *arr, size_t len) {}

}  // namespace

namespace cuda_play {
namespace simple {

template <typename T>
T reduce::reduce(T *arr, size_t len) {
  T *d_t;
  size_t size = len * sizeof(T);
  cudaMemcpy(d_t, arr, size, cudaMemcpyHostToDevice);
  T d_ret = k_reduce<<<1, 30>>>(d_t, len);
  T ret;
  cudaMemcpy(&ret, &d_ret, sizeof(T), cudaMemcpyDeviceToHost);
  return ret;
}

}  // namespace simple
}  // namespace cuda_play